{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "PyCaret Model Example"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ID</th>\n",
       "      <th>recency</th>\n",
       "      <th>history_segment</th>\n",
       "      <th>history</th>\n",
       "      <th>mens</th>\n",
       "      <th>womens</th>\n",
       "      <th>zip_code</th>\n",
       "      <th>newbie</th>\n",
       "      <th>channel</th>\n",
       "      <th>segment</th>\n",
       "      <th>visit</th>\n",
       "      <th>DM_category</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>100</td>\n",
       "      <td>10</td>\n",
       "      <td>2) $100 - $200</td>\n",
       "      <td>142.44</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>Surburban</td>\n",
       "      <td>0</td>\n",
       "      <td>Phone</td>\n",
       "      <td>Womens E-Mail</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>101</td>\n",
       "      <td>6</td>\n",
       "      <td>3) $200 - $350</td>\n",
       "      <td>329.08</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Rural</td>\n",
       "      <td>1</td>\n",
       "      <td>Web</td>\n",
       "      <td>No E-Mail</td>\n",
       "      <td>0</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>102</td>\n",
       "      <td>7</td>\n",
       "      <td>2) $100 - $200</td>\n",
       "      <td>180.65</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>Surburban</td>\n",
       "      <td>1</td>\n",
       "      <td>Web</td>\n",
       "      <td>Womens E-Mail</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>103</td>\n",
       "      <td>9</td>\n",
       "      <td>5) $500 - $750</td>\n",
       "      <td>675.83</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>Rural</td>\n",
       "      <td>1</td>\n",
       "      <td>Web</td>\n",
       "      <td>Mens E-Mail</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>104</td>\n",
       "      <td>2</td>\n",
       "      <td>1) $0 - $100</td>\n",
       "      <td>45.34</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>Urban</td>\n",
       "      <td>0</td>\n",
       "      <td>Web</td>\n",
       "      <td>Womens E-Mail</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    ID  recency history_segment  history  mens  womens   zip_code  newbie  \\\n",
       "0  100       10  2) $100 - $200   142.44     1       0  Surburban       0   \n",
       "1  101        6  3) $200 - $350   329.08     1       1      Rural       1   \n",
       "2  102        7  2) $100 - $200   180.65     0       1  Surburban       1   \n",
       "3  103        9  5) $500 - $750   675.83     1       0      Rural       1   \n",
       "4  104        2    1) $0 - $100    45.34     1       0      Urban       0   \n",
       "\n",
       "  channel        segment  visit  DM_category  \n",
       "0   Phone  Womens E-Mail      0            4  \n",
       "1     Web      No E-Mail      0           11  \n",
       "2     Web  Womens E-Mail      0            1  \n",
       "3     Web    Mens E-Mail      0            2  \n",
       "4     Web  Womens E-Mail      0            4  "
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#load data\n",
    "import pandas as pd\n",
    "\n",
    "#Load data\n",
    "dataset = pd.read_csv(r'C:\\Users\\owner\\Desktop\\direct_marketing.csv')\n",
    "\n",
    "dataset.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Data for Modeling: (60800, 12)\n",
      "Unseen Data For Predictions: (3200, 12)\n"
     ]
    }
   ],
   "source": [
    "#create unseen data for Tableau\n",
    "data = dataset.sample(frac=0.95, random_state=786).reset_index(drop=True)\n",
    "data_unseen = dataset.drop(data.index).reset_index(drop=True)\n",
    "\n",
    "new_customers = data_unseen.drop(['visit'], axis=1)\n",
    "new_customers.to_csv (r'C:\\Users\\owner\\Desktop\\new_customers.csv', index = False, header=True)\n",
    "\n",
    "print('Data for Modeling: ' + str(data.shape))\n",
    "print('Unseen Data For Predictions: ' + str(data_unseen.shape))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " \n",
      "Setup Succesfully Completed!\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<style  type=\"text/css\" >\n",
       "</style><table id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1\" ><thead>    <tr>        <th class=\"blank level0\" ></th>        <th class=\"col_heading level0 col0\" >Description</th>        <th class=\"col_heading level0 col1\" >Value</th>    </tr></thead><tbody>\n",
       "                <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row0\" class=\"row_heading level0 row0\" >0</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row0_col0\" class=\"data row0 col0\" >session_id</td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row0_col1\" class=\"data row0 col1\" >562</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row1\" class=\"row_heading level0 row1\" >1</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row1_col0\" class=\"data row1 col0\" >Target Type</td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row1_col1\" class=\"data row1 col1\" >Binary</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row2\" class=\"row_heading level0 row2\" >2</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row2_col0\" class=\"data row2 col0\" >Label Encoded</td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row2_col1\" class=\"data row2 col1\" >None</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row3\" class=\"row_heading level0 row3\" >3</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row3_col0\" class=\"data row3 col0\" >Original Data</td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row3_col1\" class=\"data row3 col1\" >(60800, 12)</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row4\" class=\"row_heading level0 row4\" >4</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row4_col0\" class=\"data row4 col0\" >Missing Values </td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row4_col1\" class=\"data row4 col1\" >False</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row5\" class=\"row_heading level0 row5\" >5</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row5_col0\" class=\"data row5 col0\" >Numeric Features </td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row5_col1\" class=\"data row5 col1\" >2</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row6\" class=\"row_heading level0 row6\" >6</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row6_col0\" class=\"data row6 col0\" >Categorical Features </td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row6_col1\" class=\"data row6 col1\" >9</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row7\" class=\"row_heading level0 row7\" >7</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row7_col0\" class=\"data row7 col0\" >Ordinal Features </td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row7_col1\" class=\"data row7 col1\" >False</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row8\" class=\"row_heading level0 row8\" >8</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row8_col0\" class=\"data row8 col0\" >High Cardinality Features </td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row8_col1\" class=\"data row8 col1\" >False</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row9\" class=\"row_heading level0 row9\" >9</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row9_col0\" class=\"data row9 col0\" >High Cardinality Method </td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row9_col1\" class=\"data row9 col1\" >None</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row10\" class=\"row_heading level0 row10\" >10</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row10_col0\" class=\"data row10 col0\" >Sampled Data</td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row10_col1\" class=\"data row10 col1\" >(60800, 12)</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row11\" class=\"row_heading level0 row11\" >11</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row11_col0\" class=\"data row11 col0\" >Transformed Train Set</td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row11_col1\" class=\"data row11 col1\" >(42559, 39)</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row12\" class=\"row_heading level0 row12\" >12</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row12_col0\" class=\"data row12 col0\" >Transformed Test Set</td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row12_col1\" class=\"data row12 col1\" >(18241, 39)</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row13\" class=\"row_heading level0 row13\" >13</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row13_col0\" class=\"data row13 col0\" >Numeric Imputer </td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row13_col1\" class=\"data row13 col1\" >mean</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row14\" class=\"row_heading level0 row14\" >14</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row14_col0\" class=\"data row14 col0\" >Categorical Imputer </td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row14_col1\" class=\"data row14 col1\" >constant</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row15\" class=\"row_heading level0 row15\" >15</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row15_col0\" class=\"data row15 col0\" >Normalize </td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row15_col1\" class=\"data row15 col1\" >False</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row16\" class=\"row_heading level0 row16\" >16</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row16_col0\" class=\"data row16 col0\" >Normalize Method </td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row16_col1\" class=\"data row16 col1\" >None</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row17\" class=\"row_heading level0 row17\" >17</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row17_col0\" class=\"data row17 col0\" >Transformation </td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row17_col1\" class=\"data row17 col1\" >False</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row18\" class=\"row_heading level0 row18\" >18</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row18_col0\" class=\"data row18 col0\" >Transformation Method </td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row18_col1\" class=\"data row18 col1\" >None</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row19\" class=\"row_heading level0 row19\" >19</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row19_col0\" class=\"data row19 col0\" >PCA </td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row19_col1\" class=\"data row19 col1\" >False</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row20\" class=\"row_heading level0 row20\" >20</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row20_col0\" class=\"data row20 col0\" >PCA Method </td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row20_col1\" class=\"data row20 col1\" >None</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row21\" class=\"row_heading level0 row21\" >21</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row21_col0\" class=\"data row21 col0\" >PCA Components </td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row21_col1\" class=\"data row21 col1\" >None</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row22\" class=\"row_heading level0 row22\" >22</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row22_col0\" class=\"data row22 col0\" >Ignore Low Variance </td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row22_col1\" class=\"data row22 col1\" >False</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row23\" class=\"row_heading level0 row23\" >23</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row23_col0\" class=\"data row23 col0\" >Combine Rare Levels </td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row23_col1\" class=\"data row23 col1\" >False</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row24\" class=\"row_heading level0 row24\" >24</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row24_col0\" class=\"data row24 col0\" >Rare Level Threshold </td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row24_col1\" class=\"data row24 col1\" >None</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row25\" class=\"row_heading level0 row25\" >25</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row25_col0\" class=\"data row25 col0\" >Numeric Binning </td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row25_col1\" class=\"data row25 col1\" >False</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row26\" class=\"row_heading level0 row26\" >26</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row26_col0\" class=\"data row26 col0\" >Remove Outliers </td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row26_col1\" class=\"data row26 col1\" >False</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row27\" class=\"row_heading level0 row27\" >27</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row27_col0\" class=\"data row27 col0\" >Outliers Threshold </td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row27_col1\" class=\"data row27 col1\" >None</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row28\" class=\"row_heading level0 row28\" >28</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row28_col0\" class=\"data row28 col0\" >Remove Multicollinearity </td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row28_col1\" class=\"data row28 col1\" >False</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row29\" class=\"row_heading level0 row29\" >29</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row29_col0\" class=\"data row29 col0\" >Multicollinearity Threshold </td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row29_col1\" class=\"data row29 col1\" >None</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row30\" class=\"row_heading level0 row30\" >30</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row30_col0\" class=\"data row30 col0\" >Clustering </td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row30_col1\" class=\"data row30 col1\" >False</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row31\" class=\"row_heading level0 row31\" >31</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row31_col0\" class=\"data row31 col0\" >Clustering Iteration </td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row31_col1\" class=\"data row31 col1\" >None</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row32\" class=\"row_heading level0 row32\" >32</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row32_col0\" class=\"data row32 col0\" >Polynomial Features </td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row32_col1\" class=\"data row32 col1\" >False</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row33\" class=\"row_heading level0 row33\" >33</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row33_col0\" class=\"data row33 col0\" >Polynomial Degree </td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row33_col1\" class=\"data row33 col1\" >None</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row34\" class=\"row_heading level0 row34\" >34</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row34_col0\" class=\"data row34 col0\" >Trignometry Features </td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row34_col1\" class=\"data row34 col1\" >False</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row35\" class=\"row_heading level0 row35\" >35</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row35_col0\" class=\"data row35 col0\" >Polynomial Threshold </td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row35_col1\" class=\"data row35 col1\" >None</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row36\" class=\"row_heading level0 row36\" >36</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row36_col0\" class=\"data row36 col0\" >Group Features </td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row36_col1\" class=\"data row36 col1\" >False</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row37\" class=\"row_heading level0 row37\" >37</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row37_col0\" class=\"data row37 col0\" >Feature Selection </td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row37_col1\" class=\"data row37 col1\" >False</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row38\" class=\"row_heading level0 row38\" >38</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row38_col0\" class=\"data row38 col0\" >Features Selection Threshold </td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row38_col1\" class=\"data row38 col1\" >None</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row39\" class=\"row_heading level0 row39\" >39</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row39_col0\" class=\"data row39 col0\" >Feature Interaction </td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row39_col1\" class=\"data row39 col1\" >False</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row40\" class=\"row_heading level0 row40\" >40</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row40_col0\" class=\"data row40 col0\" >Feature Ratio </td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row40_col1\" class=\"data row40 col1\" >False</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1level0_row41\" class=\"row_heading level0 row41\" >41</th>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row41_col0\" class=\"data row41 col0\" >Interaction Threshold </td>\n",
       "                        <td id=\"T_cdded55c_9e3c_11ea_a7af_7085c2286cd1row41_col1\" class=\"data row41 col1\" >None</td>\n",
       "            </tr>\n",
       "    </tbody></table>"
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x274f5148408>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#pycaret setup\n",
    "from pycaret.classification import *\n",
    "clf = setup(data, target = 'visit', session_id=562, ignore_features=['ID'], silent = True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Accuracy</th>\n",
       "      <th>AUC</th>\n",
       "      <th>Recall</th>\n",
       "      <th>Prec.</th>\n",
       "      <th>F1</th>\n",
       "      <th>Kappa</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.7655</td>\n",
       "      <td>0.6296</td>\n",
       "      <td>0.2540</td>\n",
       "      <td>0.2304</td>\n",
       "      <td>0.2416</td>\n",
       "      <td>0.1033</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.7636</td>\n",
       "      <td>0.6306</td>\n",
       "      <td>0.2552</td>\n",
       "      <td>0.2289</td>\n",
       "      <td>0.2413</td>\n",
       "      <td>0.1018</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.7657</td>\n",
       "      <td>0.6220</td>\n",
       "      <td>0.2584</td>\n",
       "      <td>0.2334</td>\n",
       "      <td>0.2453</td>\n",
       "      <td>0.1070</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.7570</td>\n",
       "      <td>0.6056</td>\n",
       "      <td>0.2297</td>\n",
       "      <td>0.2072</td>\n",
       "      <td>0.2179</td>\n",
       "      <td>0.0745</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.7592</td>\n",
       "      <td>0.6009</td>\n",
       "      <td>0.2185</td>\n",
       "      <td>0.2039</td>\n",
       "      <td>0.2109</td>\n",
       "      <td>0.0690</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0.7629</td>\n",
       "      <td>0.6212</td>\n",
       "      <td>0.2265</td>\n",
       "      <td>0.2132</td>\n",
       "      <td>0.2196</td>\n",
       "      <td>0.0800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>0.7585</td>\n",
       "      <td>0.6076</td>\n",
       "      <td>0.2281</td>\n",
       "      <td>0.2082</td>\n",
       "      <td>0.2177</td>\n",
       "      <td>0.0752</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>0.7674</td>\n",
       "      <td>0.6182</td>\n",
       "      <td>0.2648</td>\n",
       "      <td>0.2388</td>\n",
       "      <td>0.2511</td>\n",
       "      <td>0.1139</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>0.7646</td>\n",
       "      <td>0.6058</td>\n",
       "      <td>0.2504</td>\n",
       "      <td>0.2279</td>\n",
       "      <td>0.2386</td>\n",
       "      <td>0.0997</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>0.7448</td>\n",
       "      <td>0.5960</td>\n",
       "      <td>0.2316</td>\n",
       "      <td>0.1933</td>\n",
       "      <td>0.2108</td>\n",
       "      <td>0.0600</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Mean</th>\n",
       "      <td>0.7609</td>\n",
       "      <td>0.6137</td>\n",
       "      <td>0.2417</td>\n",
       "      <td>0.2185</td>\n",
       "      <td>0.2295</td>\n",
       "      <td>0.0885</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>SD</th>\n",
       "      <td>0.0063</td>\n",
       "      <td>0.0115</td>\n",
       "      <td>0.0156</td>\n",
       "      <td>0.0144</td>\n",
       "      <td>0.0147</td>\n",
       "      <td>0.0177</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      Accuracy     AUC  Recall   Prec.      F1   Kappa\n",
       "0       0.7655  0.6296  0.2540  0.2304  0.2416  0.1033\n",
       "1       0.7636  0.6306  0.2552  0.2289  0.2413  0.1018\n",
       "2       0.7657  0.6220  0.2584  0.2334  0.2453  0.1070\n",
       "3       0.7570  0.6056  0.2297  0.2072  0.2179  0.0745\n",
       "4       0.7592  0.6009  0.2185  0.2039  0.2109  0.0690\n",
       "5       0.7629  0.6212  0.2265  0.2132  0.2196  0.0800\n",
       "6       0.7585  0.6076  0.2281  0.2082  0.2177  0.0752\n",
       "7       0.7674  0.6182  0.2648  0.2388  0.2511  0.1139\n",
       "8       0.7646  0.6058  0.2504  0.2279  0.2386  0.0997\n",
       "9       0.7448  0.5960  0.2316  0.1933  0.2108  0.0600\n",
       "Mean    0.7609  0.6137  0.2417  0.2185  0.2295  0.0885\n",
       "SD      0.0063  0.0115  0.0156  0.0144  0.0147  0.0177"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#create model\n",
    "nb = create_model('nb')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Transformation Pipeline and Model Succesfully Saved\n"
     ]
    }
   ],
   "source": [
    "#finalize model (use all data to train)\n",
    "nb_final = finalize_model(nb)\n",
    "\n",
    "#save model and transformation pipeline\n",
    "save_model(nb_final, 'C:/Users/owner/Desktop/nb_direct')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
